<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/10 13:55
 * Modified Time: 2019/7/10 13:55
 * Version: 2.0
 */

namespace App\Modules\Inventory\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetGoodsCriteria extends BaseCriterias
{
    protected $goods_id;

    public function __construct($goods_id)
    {
        $this->goods_id = $goods_id;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $goods_id = $this->goods_id;

        $model = $model
            ->select([
                'id',
                'name',
                'small_name',
                'cat_id',
                'buying_price',
                'market_price',
                'royalty',
                'is_sell',
                'specs',
                'volume',
                'image',
                'store_id',
            ])
            ->with(['image'=>function($query){
                $query->select('id','image');
            }])
            ->with(['goodsCategory'=>function($query){
                $query->select('id','name');
            }])
            ->with(['store' => function ($query) {
                $query->select(['id', 'alipay', 'wxpay'])
                ->with(['alipay','wxpay']);
            }])
            ->where('goods.id', $goods_id)
            ->orderBy('id', 'DESC');


        return $model;
    }
}